//
//  AppDelegate.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/6/6.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "AppDelegate.h"
#import "AppDelegate+YCPayDelegate.h"
#import "AppDelegate+YCUMSocialDelegate.h"
#import "YCTabbarViewController.h"
#import "YCLoginViewController.h"
#import "YCSSKeychain.h"
#import "MBProgressHUD.h"
#import <UMSocialCore/UMSocialCore.h>
#import "LoginViewController.h"
#import "YCNavViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    self.window.backgroundColor = [UIColor whiteColor];
    //放慢启动图片
    [NSThread sleepForTimeInterval:1.0];

    //设置导航栏的全局色
    [self setBarTinColor];
    [self setRootVc];
    [self yc_setupUMSocial:launchOptions application:application];
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)setRootVc {
    

    NSString *userPhone = [[NSUserDefaults standardUserDefaults] valueForKey:KLINKMOBILE];

    //微信支付@"wxcdc5a74a0d127b83"
    [WXApi registerApp:AppID withDescription:APP_DESC];
    
    NSLog(@"%@",[YCSSKeychain getValueforkey:userPhone]);
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:KEXPERTID] == nil) {
        
        LoginViewController *loginVc = [[LoginViewController alloc]init];
        
        YCNavViewController * nav = [[YCNavViewController alloc] initWithRootViewController:loginVc];
        self.window.rootViewController = nav;
        
    } else {
    
         [YCUserTool sharedTools].linkMobile =  [[NSUserDefaults standardUserDefaults]objectForKey:KLINKMOBILE];;
      
         [YCUserTool sharedTools].expertID = [[NSUserDefaults standardUserDefaults]objectForKey:KEXPERTID];
        
         [YCUserTool sharedTools].checkFlag = [[NSUserDefaults standardUserDefaults]objectForKey:KCHECKFLAG];
        
        YCTabbarViewController *hoVC = [[YCTabbarViewController alloc]init];
       
        self.window.rootViewController = hoVC;
    
    }
    
//    if ([YCSSKeychain getValueforkey:userPhone]==nil||[[YCSSKeychain getValueforkey:userPhone] isEqualToString:@"**"]) {
//
//        YCLoginViewController *loginVc = [[YCLoginViewController alloc]init];
//        self.window.rootViewController = loginVc;
//
//    }else{
//
//
//    }

}
-(void)setBarTinColor {
    
    [UINavigationBar.appearance setTintColor:[UIColor whiteColor]];
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    
    for (UIView  * hud in [UIApplication sharedApplication].keyWindow.subviews)
    {
        if ([hud isKindOfClass:[MBProgressHUD class]])
        {
            [[UIApplication sharedApplication].keyWindow dismissTips];
        }
    }
    

}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
        // 其他如支付等SDK的回调
        [self setUpPaySDKWithUrl:url];
    }
    return YES;
    
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
    BOOL result = [[UMSocialManager defaultManager]  handleOpenURL:url options:options];
    if (!result) {
        // 其他如支付等SDK的回调
        [self setUpPaySDKWithUrl:url];
    }
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (!result) {
        // 其他如支付等SDK的回调
        [self setUpPaySDKWithUrl:url];
    }
    return YES;
}









@end
